<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>node.js 模块之 pm2 | 云飞扬 - 个人博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="pm2 简介pm2 是一个带有负载均衡功能的Node应用的进程管理器.当你要把你的独立代码利用全部的服务器上的所有CPU，并保证进程永远都活着，0秒的重载， PM2是完美的。它非常适合IaaS结构，但不要把它用于PaaS方案（随后将开发Paas的解决方案）.
常用命令pm2 升级123pm2 savenpm install -g pm2pm2 update
全局安装1npm install -g">
<meta property="og:type" content="article">
<meta property="og:title" content="node.js 模块之 pm2">
<meta property="og:url" content="http://blog.yxxit.com/2017/02/17/node.js 模块之 pm2/index.html">
<meta property="og:site_name" content="云飞扬 - 个人博客">
<meta property="og:description" content="pm2 简介pm2 是一个带有负载均衡功能的Node应用的进程管理器.当你要把你的独立代码利用全部的服务器上的所有CPU，并保证进程永远都活着，0秒的重载， PM2是完美的。它非常适合IaaS结构，但不要把它用于PaaS方案（随后将开发Paas的解决方案）.
常用命令pm2 升级123pm2 savenpm install -g pm2pm2 update
全局安装1npm install -g">
<meta property="og:updated_time" content="2017-02-17T04:16:55.625Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="node.js 模块之 pm2">
<meta name="twitter:description" content="pm2 简介pm2 是一个带有负载均衡功能的Node应用的进程管理器.当你要把你的独立代码利用全部的服务器上的所有CPU，并保证进程永远都活着，0秒的重载， PM2是完美的。它非常适合IaaS结构，但不要把它用于PaaS方案（随后将开发Paas的解决方案）.
常用命令pm2 升级123pm2 savenpm install -g pm2pm2 update
全局安装1npm install -g">
  
    <link rel="alternate" href="/atom.xml" title="云飞扬 - 个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/view/favicon.ico">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/view/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/view/" id="logo">云飞扬 - 个人博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/view/">Home</a>
        
          <a class="main-nav-link" href="/view/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://blog.yxxit.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-node.js 模块之 pm2" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/view/2017/02/17/node.js 模块之 pm2/" class="article-date">
  <time datetime="2017-02-17T04:02:41.926Z" itemprop="datePublished">2017-02-17</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      node.js 模块之 pm2
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="pm2-简介"><a href="#pm2-简介" class="headerlink" title="pm2 简介"></a>pm2 简介</h2><p>pm2 是一个带有负载均衡功能的Node应用的进程管理器.<br>当你要把你的独立代码利用全部的服务器上的所有CPU，并保证进程永远都活着，0秒的重载， PM2是完美的。它非常适合IaaS结构，但不要把它用于PaaS方案（随后将开发Paas的解决方案）.</p>
<h2 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h2><h2 id="pm2-升级"><a href="#pm2-升级" class="headerlink" title="pm2 升级"></a>pm2 升级</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">pm2 save</div><div class="line">npm install -g pm2</div><div class="line">pm2 update</div></pre></td></tr></table></figure>
<h3 id="全局安装"><a href="#全局安装" class="headerlink" title="全局安装"></a>全局安装</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install -g pm2</div></pre></td></tr></table></figure>
<h3 id="开启进程"><a href="#开启进程" class="headerlink" title="开启进程"></a>开启进程</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">pm2 start app.js -i 3 --name node-api # 开启3个名称为node-api的进程</div><div class="line">pm2 start app.js -i max --name node-api # 根据有效CPU数目启动最大进程数目</div><div class="line">pm2 monit # 监视所有进程</div><div class="line">pm2 list # 显示所有进程状态</div><div class="line">pm2 logs node-api # 查看进程日志 默认查看所有</div><div class="line">pm2 stop all # 停止所有进程</div><div class="line">pm2 restart all # 重启所有进程</div><div class="line">pm2 reload all # 0秒停机重载进程 (用于 NETWORKED 进程)</div><div class="line">pm2 delete all # 杀死全部进程</div><div class="line">pm2 startup # 产生 init 脚本 保持进程活着</div><div class="line">pm2 web # 运行健壮的 computer API endpoint (http://localhost:9615)</div><div class="line">pm2 start app.js -x #用fork模式启动 app.js 而不是使用 cluster</div><div class="line">pm2 start app.js -x -- -a 23 # 用fork模式启动 app.js 并且传递参数 (-a 23)</div><div class="line">pm2 start app.json # 启动进程, 在 app.json里设置选项</div></pre></td></tr></table></figure>
<h3 id="支持CoffeeScript"><a href="#支持CoffeeScript" class="headerlink" title="支持CoffeeScript:"></a>支持CoffeeScript:</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pm2 start my_app.coffee</div></pre></td></tr></table></figure>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul>
<li><a href="https://www.douban.com/note/314200231/" target="_blank" rel="external">PM2 介绍</a></li>
<li><a href="https://github.com/Unitech/pm2" target="_blank" rel="external">PM2 官方文档</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://blog.yxxit.com/view/2017/02/17/node.js 模块之 pm2/" data-id="ciz9b0a650000cgdd5t8ywr1z" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/view/2017/03/05/windows nginx natapp/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          windows nginx natapp
        
      </div>
    </a>
  
  
    <a href="/view/2017/02/16/node.js 6.9.4 升级/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">node.js 6.9.4 升级</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/view/tags/node-js-规范/">node.js, 规范</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/view/tags/node-js-规范/" style="font-size: 10px;">node.js, 规范</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/view/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/view/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/view/archives/2017/01/">January 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/view/2017/03/21/npm/">npm 常用命令</a>
          </li>
        
          <li>
            <a href="/view/2017/03/21/git/">Git 常用命令</a>
          </li>
        
          <li>
            <a href="/view/2017/03/05/windows nginx natapp/">windows nginx natapp</a>
          </li>
        
          <li>
            <a href="/view/2017/02/17/node.js 模块之 pm2/">node.js 模块之 pm2</a>
          </li>
        
          <li>
            <a href="/view/2017/02/16/node.js 6.9.4 升级/">node.js 6.9.4 升级</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 coolshaw<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/view/" class="mobile-nav-link">Home</a>
  
    <a href="/view/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>


  <link rel="stylesheet" href="/view/fancybox/jquery.fancybox.css">
  <script src="/view/fancybox/jquery.fancybox.pack.js"></script>


<script src="/view/js/script.js"></script>

  </div>
</body>
</html>